<template>
    <!-- 组件的模板 -->
    <div class="main">
        <div class="withdrawalway mg_rl12" v-if="bindList.length > 0">
            <a href="javascript:;" v-for="item in bindList" >
                <img src="../../static/imgs/bj_1.png" v-if="item.account_type == 1">
                <!-- 微信提现下版上 -->
                <!-- <img src="../../static/imgs/bj_2.png" v-if="item.account_type == 2"> -->
                <img src="../../static/imgs/bj_3.png" v-if="item.account_type == 3">
                <div class="withdrawal_list">
                    <div class="list_left clfff" @click="checkRealname(item.account_type,item.is_bind)">
                        <p class="ft18" v-if="item.account_type != 2">{{item.name}}</p> 
                        <p class="ft14" v-if="item.account_type == 1 && item.is_bind == 1">
                            <span class="phone_begin">{{phone_begin}}</span>
                            <span class="hide_phone"></span>
                            <span class="phone_end">{{phone_end}}</span>
                        </p>
                        <p class="ft14" v-if="item.account_type == 3 && item.is_bind == 1">
                            <span class="hide_phone2"></span>
                            <span class="hide_phone2"></span>
                            <span class="hide_phone2"></span>
                            <span class="phone_end">{{bankNumber}}</span>
                        </p>   
                        <p class="ft14" v-if="item.account_type == 1 && item.is_bind != 1">未绑定</p>   
                        <p class="ft14" v-if="item.account_type == 3 && item.is_bind != 1">未绑定</p>   
                        <!-- 微信提现下版上 -->
                        <!-- <p class="ft14" v-if="item.account_type == 2">{{item.is_bind == 1 ? item.account : '未绑定'}}</p>    -->
                    </div>
                    <div class="list_right" v-if="item.account_type != 2">
                        <i v-if="item.is_bind == 1" class="db untie" @click="untie(item.account_type,item.name)">解绑</i>
                        <i v-else class="db go_withdrawal"></i>
                    </div>
                </div>
            </a>                     
        </div>

        
        <!-- <p class="withdraw_tip">提现金额：支付宝>0元，微信>=1元，银行卡>=50元</p> -->
        <p class="withdraw_tip">提现金额：支付宝>0元，银行卡>=50元</p>
    </div>
        
</template>

<script>
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */
    
    import commonPage from 'clientApi/commonPage.js'
    import cache from 'gapi/cache.js'
    import * as util from 'js/util.js'
    import widget from 'gapi/widget'
    import clientUi from 'gapi/clientUi.js'
    import clientUtil from 'clientApi/util'
    import userCenterApi from 'clientApi/userCenterApi'
    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */

    /**
     *  组件实例对象
     */
    export default {
        components: {

        },
        data: function(){
            return{
                bindList:[],
                bindOrWithdrawal:false,
                is_bindIdCard:true,
                phone_begin: '',
                phone_end: '',
                bankNumber: '',
                real_name: '',
            }
        },
        vuex: {
            getters: {

            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){
                commonPage.loadPageStatus('loading')
 
                util.ajax({
                    url:'/wallet/withdraw/mode/get',
                    type:'GET',
                    data:{
                        'team_id': 0,
                        'project_id': 0,
                    },
                    timeout:10000,
                    success:(data) => {
                        commonPage.loadPageStatus('loadSuccess')
                        if(data.errno == 0){
                            this.bindList = data.data;
                            this.bindList.forEach((obj) =>{
                                if(obj.account_type == 1){
                                    let phone = obj.account;
                                    this.phone_begin = phone.substr(0, 3)
                                    this.phone_end =  phone.substr(7)
                                }else if(obj.account_type == 3){
                                    let bankNumber = obj.account;
                                    this.bankNumber = bankNumber.substr(-4)
                                }
                            })
                        }else{
                            widget.toast(data.errmsg)
                        }
                    },
                    error:function(status){
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                    }
                })
   
            },
            //检测是否进行了实名认证
            checkRealname(type,is_bind){
                commonPage.loadPageStatus('loading') 
                let junUrl;
                switch(type){
                    case '1':
                        junUrl = 'BindingAlipay'
                        break;
                    case '2':
                        junUrl = 'BindingWxpay'
                        break;
                    case '3':
                        junUrl = 'BindingBankcard'
                        break;
                }               
                util.ajax({
                    url:'/user/check_real_name_authentication',
                    type:'GET',
                    data:{},
                    timeout:10000,
                    success:(data) => {
                        commonPage.loadPageStatus('loadSuccess')
                        // alert(JSON.stringify(data))
                        if(data.errno == 0){
                            this.real_name = data.data.real_name
                            if(data.data.authenticated == 1){
                                if(is_bind == 0){
                                    if(type == 2){
                                         userCenterApi.getWxInfo(data =>{   
                                            if(data.status == 1){         
                                                let encodeStr = encodeURIComponent(`last_pageUrl=${type}&real_name=${this.real_name}`)
                                                location.href = `dmsaas://${junUrl}?urdData=${encodeStr}`;
                                            }else{
                                                return
                                            }
                                        })
                                    }else{
                                        let encodeStr = encodeURIComponent(`last_pageUrl=${type}&real_name=${this.real_name}`)
                                        location.href = `dmsaas://${junUrl}?urdData=${encodeStr}`;
                                    }
                                    
                                }else{
                                    let encodeStr = encodeURIComponent(`last_pageUrl=${type}&real_name=${this.real_name}`)
                                    location.href = `dmsaas://ApplyforWithdrawal?urdData=${encodeStr}`
                                }
                            }else{
                                let encodeStr = encodeURIComponent(`last_pageUrl=${type}&real_name=${this.real_name}`)
                                location.href = `dmsaas://BindinGidcard?urdData=${encodeStr}`
                            }
                        }else{
                            widget.toast(data.errmsg)
                        }
                    },
                    error:function(status){
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                    }
                })
            },
            //解除绑定
            untie(account_type,account_name){
                commonPage.loadPageStatus('loading')

                clientUi.showDialog('解绑', '是否确认解绑'+ account_name +'账户？', (status) => {
                    if(status.status == 1){
                        util.ajax({
                            url:'/wallet/remove_bind',
                            type:'POST',
                            data:{
                                account_type: account_type,
                            },
                            timeout:10000,
                            success:(data) => {
                                if(data.errno == 0){
                                    widget.toast('解绑成功')
                                    this.init()
                                }else{
                                    widget.toast(data.errmsg)
                                }
                            },
                            error: (xhr, status) => {
                                widget.toast('服务器异常')
                            },
                            noNetwork: () => {
                                widget.toast('网络连接失败，请检查网络')
                            }
                        })
                    }
                    commonPage.loadPageStatus('loadSuccess')

                }, '确认', '取消')
                
                
            }
        },
        created(){
            
            this.init();
            commonPage.updateTitleBar({
                backAction: 'goBack',
                leftAction: 'goBack'
            })
            window.goBack = () => {
                // location.href = "dmsaas://MyWallet"
                cache.getMemoryCache('yyMywalletWebViewID',function(data){
                    if(data){
                        commonPage.goBack(1, {}, data.webViewID)
                    }
                })
            }
            commonPage.getWebViewID((data)=>{
              cache.setMemoryCache('yyWithdrayalwayWebViewID',{'webViewID':data})
            })
        }
        
    }

    
</script>

<!-- CSS 样式 -->
<!-- <style src="static/css/global.css"></style> -->
<style src="../../static/css/base.css"></style>
<style src="../../static/css/yy_withdrawalWay.css"></style>



